<script src="Libraries/js/js.js"></script>
<script type="text/javascript" src="Libraries/nicEdit/nicEdit.js"></script>
<script type="text/javascript">
	bkLib.onDomLoaded(function() { nicEditors.allTextAreas() });
	//bkLib.onDomLoaded(function() { var area1 = new nicEditor({fullPanel : true}).panelInstance('txtnoidung',{hasPanel : true}); });
</script>

<script language="javascript">

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
//nicEditors.findEditor('txtnoidung').setContent("");
function getValue(id){
    document.capnhatdcct.txtmahp.readOnly=true;
	//document.capnhatdcct.txtmadc.value = document.getElementById("madc" + id).innerHTML;
    document.capnhatdcct.txtmadc.value = document.getElementById("madc" + id).innerHTML;
    document.capnhatdcct.txtnoidungvt.value = document.getElementById("noidungvt" + id).innerHTML;
    document.capnhatdcct.txtsotiet.value = document.getElementById("sotiet" + id).innerHTML;
    document.capnhatdcct.txtchuthich.value = document.getElementById("ghichu" + id).innerHTML;
	nicEditors.findEditor('txtnoidung').setContent("");
    var noidung = document.getElementById("noidung" + id).innerHTML;
    nicEditors.findEditor('txtnoidung').setContent(noidung);
    document.capnhatdcct.btnthem.disabled = true;
    document.capnhatdcct.btnsua.disabled = false;
    document.capnhatdcct.btnxoa.disabled = false;
}
function checkValue(){
	
	var noidung = nicEditors.findEditor('txtnoidung').getContent();
	
	if (document.capnhatdcct.txtmahp.value == "" || document.capnhatdcct.txtmadc.value == ""){
		alert ("Xin vui lòng nhập mã học phần!");
		document.capnhatdcct.txtmahp.focus();
		return false;
	}
	if (document.capnhatdcct.txtmahp.value.length > 5){
		alert ("Mã học phần có chiều dài không quá 5 kí tự!");
		document.capnhatdcct.txtmahp.focus();
		return false;
	}
	
	if (isDigit(document.capnhatdcct.txtsotiet.value) == false){
		alert ("Số tiết là một số nguyên!")
		document.capnhatdcct.txtsotiet.focus();
		return false;
	}
	if (document.capnhatdcct.txtnoidungvt.value == ""){
		alert ("Xin vui lòng nhập nội dung vắn tắt!")
		return false;
	}
	if (noidung.length == 4){
		//alert (trim(document.capnhatdcct.txtnoidung.value).length);
		alert ("Xin vui lòng nhập nội dung!");
		document.capnhatdcct.txtnoidung.focus();
		return false;
	}
	return true;
	//alert (noidung.length);
	//return false;
}
function taoMoi(){
    //document.capnhatdcct.chkchon.checked = false;
    //document.capnhatdcct.txtmahp.value = "";
	 document.capnhatdcct.txtmahp.readOnly=false;
	document.capnhatdcct.txtmadc.value = "";
    document.capnhatdcct.txtsotiet.value = "";
    document.capnhatdcct.txtchuthich.value = "";
    document.capnhatdcct.txtnoidungvt.value = "";
    document.capnhatdcct.txtnoidung.value = "";
    nicEditors.findEditor('txtnoidung').setContent("<br>");
    document.capnhatdcct.btnthem.disabled = false;
    document.capnhatdcct.btnsua.disabled = true;
    document.capnhatdcct.btnxoa.disabled = true;
   	if (document.capnhatdcct.chkchon.length > 0){
			for (var i=0; i<document.capnhatdcct.chkchon.length; i++){
				
				
				if ( document.capnhatdcct.chkchon[i].checked == true){
					document.capnhatdcct.chkchon[i].checked = false;
					break;
				}
				
			}
			
		}
		else {
			if ( document.capnhatdcct.chkchon.checked == true){
				document.capnhatdcct.chkchon.checked =false; 
			}
		}
		hienThiDCCTCuaHP(document.capnhatdcct.txtmahp.value);
}
function confirmDelete(){
    if (confirm("Bạn có chắc muốn xóa đề cương chi tiết này không?")){
        return true;
    }
    return false;
    
}
function confirmUpdate(){
    if (confirm("Bạn có chắc muốn xóa đề cương chi tiết này không?")){
        return checkValue();
    }
    return false;
    
}
</script>

<link href="Libraries/css/style.css" rel="stylesheet" type="text/css" />
<form name="capnhatdcct" method="POST" >
<table align="center" class="font" width="800" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class=main_1><img border="0" src="Libraries/images/tbl_left.gif" width="10" height="25" /></td>
    <td align=center class=main_1>Cập Nhật Đề Cương Chi Tiết Học Phần</td>
    <td class=main_1><p align="right"><img border="0" src="Libraries/images/tbl_right.gif" width="10" height="25" /></p></td>
  </tr>
  <tr bgcolor="#dae9f3">
    <td class="border_1" colspan="3" valign="top">
        <table border="0" align="center">
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td><a href="#"></a></td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td align="right">Mã HP</td>
            <td colspan="5"><input name="txtmahp" type="text" id="txtmahp" onkeyup="hienThiDCCTCuaHP(this.value);" value="<?php echo trim($mahp)?>" size="10"/>&nbsp;&nbsp;Mã ĐC 
            <input name="txtmadc" type="text" id="txtmadc" size="10" readonly="true" style="background: #CCCCCC" value="<?php echo trim($madc)?>"/>&nbsp;&nbsp;Số tiết&nbsp;&nbsp;
            <input name="txtsotiet" type="text" id="txtsotiet" size="5" value="<?php echo trim($sotiet)?>"/></td>
          </tr>
          <tr>
            <td align="right">Ghi chú </td>
            <td colspan="5" align="left"><input name="txtchuthich" type="text" id="txtchuthich" size="80" value="<?php echo trim($ghichu)?>"/></td>
          </tr>
          <tr>
            <td align="left">Nội dung vắt tắt</td>
            <td colspan="5"><input name="txtnoidungvt" type="text"  value="<?php echo trim($noidungvt)?>" size="80" /></td>
          </tr>
          
          <tr>
            <td valign="top" align="right">Nội dung</td>
            <td colspan="5"><textarea name="txtnoidung" cols="60" rows="5" id="txtnoidung"><?php echo trim($noidung)?></textarea></td>
          </tr>
          <tr>
            <td colspan="6" align="center"><input name="btntaomoi" type="button" class="button_1" id="btntaomoi" value="Tạo mới" onclick="taoMoi();"/>
              <input type="submit" name="btnthem" value="Thêm" class="button_1" onclick="return checkValue();"/>
              <input type="submit" name="btnsua" value="Sửa" class="button_1" disabled="disabled" onclick="return confirmUpdate();"/>
            <input type="submit" name="btnxoa" value="Xóa" class="button_1" disabled="disabled" onclick="return confirmDelete();"/></td>
          </tr>
        </table>
    </td>
  </tr>
  </table>
   
<br />
<div id="decuong">
<?php
include_once('Models/HocPhan.php');
include_once('Models/DeCuongHPChiTiet.php');
if ($_SERVER['REQUEST_METHOD'] == 'POST') 
{
	$hp = new HocPhan();
    $hp->setMaHP($mahp);
	$result = $hp->dsDeCuongHPChiTiet();
	$num = mysql_num_rows($result);
	//echo $dcct->getQuery();
	/*if ($num <= 0) 
	{
		include_once('Models/HocPhan.php');
		$hp = new HocPhan();
		if ($hp->isExits("HocPhan","mahp='".$mahp."'")>0){
			echo $mahp.'1'.'|';
		}
		
	}*/
	if ($num > 0)
	{
		
		
		echo "<table align='center' class='font' width='700' border='0' cellspacing='0' cellpadding='0'>";
		  echo "<tr>";
			echo "<td class='main_1'><img border='0' src='Libraries/images/tbl_left.gif' width='10' height='25' /></td>";
			echo "<td align='center' class='main_1'>Danh sách Đề cương học phần chi tiết </td>";
			echo "<td class='main_1'><p align='right'><img border='0' src='Libraries/images/tbl_right.gif' width='10' height='25' /></p></td>";
		  echo "</tr>";
		  echo "<tr >";
				echo "<td class='border_1' colspan='3' valign='top'>";
					echo "<table width='800' border='0' align='center' cellpadding='0' cellspacing='0'>";
						echo "<tr>";
							echo "<td width='60' class='main_3' align='center'><strong>Mã ĐC </strong></td>";
							echo "<td align='center' width='200' class='main_3' align='center'><strong>Nội dung tắt</strong></td>";
							echo "<td align='center' width='400' class='main_3' align='center'><strong>N&#7897;i dung: </strong></td>";
							echo "<td width='70' class='main_3' align='center'><strong>S&#7889; ti&#7871;t </strong></td>";
							echo "<td width='70' class='main_3' align='center'><strong>Ghi chú </strong></td>";
							echo "<td width='70' class='main_3' align='center'><strong>Chọn</strong></td>";
						echo "</tr>";
								
						$i=0;
									
						while ($record = mysql_fetch_array($result))
						{    
							$i++;
							 $ci = 2-$i%2;       
						echo "<tr>";
							echo "<td  class='level_1_$ci'><div id='madc$i'>".$record['madc']."</div></td>";
							echo "<td  class='level_1_$ci'><div id='noidungvt$i'>".$record['noidungvt']."</div></td>";
							echo "<td  class='level_1_$ci'><div id='noidung$i'>".$record['noidung']."</div></td>";
							echo "<td  class='level_1_$ci' align='center'><div id='sotiet$i'>".$record['sotiet']."</div></td>";
							echo "<td  class='level_1_$ci' align='center'>&nbsp;<div id='ghichu$i'>".$record['ghichu']."</div></td>";
							echo "<td  class='level_1_$ci' align='center'><input type='radio' name='chkchon' value=$i onClick='getValue(this.value);' ></td>";       
						echo "</tr>";
 
					}
							   
					echo "</table>";
				echo "</td>";
			echo "</tr >";
		echo "</table>";
	}
	else
	{
		
		include_once('Models/HocPhan.php');
		$hp = new HocPhan();
		if ($hp->isExits("HocPhan","mahp='".$mahp."'")>0){
			
			echo "<table align='center' class='font' width='800' border='0' cellspacing='0' cellpadding='0'>";
			  echo "<tr>";
				echo "<td class='main_1'><img border='0' src='Libraries/images/tbl_left.gif' width='10' height='25' /></td>";
				echo "<td align='center' class='main_1'>Đề cương học phần chi tiết </td>";
				echo "<td class='main_1'><p align='right'><img border='0' src='Libraries/images/tbl_right.gif' width='10' height='25' /></p></td>";
			  echo "</tr>";
			  echo "<tr >";
					echo "<td class='border_1' colspan='3' valign='top'>";
					echo "<tc> Chưa có đề cương chi tiết</td>";    
					echo "</td>";
				echo "</tr >";
			echo "</table>";
		}
		else
		{
			
			echo "<table width='800' border='0' align='center' cellpadding='20'>";
				echo "<tr>";
					echo "<td  class='main_3' align='center'><strong>Không tồn tại học phần này </strong></td>";
					
				echo "</tr>";
						
							
				
			echo "</table>";
		}
		
	}
}
?>
</div>

</form>


